<?php

$name = getInputArray("name", $params,'');
$id = getInputArray("id", $params,str_replace(".","",str_replace(" ","",microtime())));
$labelid = str_replace(".","",str_replace(" ","",microtime()));
$value = getInputArray("value", $params,'');
$options = getInputArray("options", $params,array());
$class = getInputArray("class", $params,'');
$validate = getInputArray("validate", $params,'');
$required = getInputArray("required", $params,false);
$messageRequired = getInputArray("messageRequired", $params,langEcho("messageRequired"));
$sort = getInputArray("sort", $params,false);
$firstOption = getInputArray("firstOption", $params,array());
$size = getInputArray("size", $params, 1);
$onClick = getInputArray("onclick", $params, "");
$onChange = getInputArray("onchange", $params, "");

if ($sort){
	$tempOptions = array();
	foreach($options as $key => $text){
		$tempOptions[$key] = langEcho($text);
	}
	asort($tempOptions);
	$options = $tempOptions;	
}

$requiredString = "false";
if($required){
	$requiredString = "true";
}

?>
 
<?php
echo "<select "; 
if ($name != "") echo " name='" . $name ."' ";
 
if ($id != "") echo " id='" . $id ."' ";

if ($class != "") echo " class='" . $class ."' ";

echo " size=$size ";

if ($onChange) echo " onchange=$onChange";

if ($onClick) echo " onclick=$onClick";

echo ">";
if ($firstOption){
	foreach($firstOption as $key => $text){
		echo "<option value='$key'>".langEcho($text)."</option>";
	}
}
foreach($options as $key => $text){
	echo "<option value='$key'>";
	if ($sort){
		echo $text;
	}else{
		echo langEcho($text);
	}
	echo "</option>";
}

echo "</select><span class='validateTextbox' id='".$labelid."' ></span>";
echo '<script type="text/javascript">';
echo "var select = document.getElementById('$id');		
		for(i = 0; i< select.length;i++){		
			if(select.options[i].value == '$value'){			
				select.options[i].selected = true;
			}
		}";
echo '</script>';

if($validate != ''){
echo '<script type="text/javascript">';
echo "registerValidation('$validate', '$id',$requiredString, 'select', '$labelid', '$messageRequired', '', '')";
echo '</script>';
}

?>